package com.hckjsec.official.service;

import com.hckjsec.common.constant.Constants;
import com.hckjsec.common.utils.DateUtils;
import com.hckjsec.common.utils.LogUtils;
import com.hckjsec.common.utils.ServletUtils;
import com.hckjsec.common.utils.ip.AddressUtils;
import com.hckjsec.common.utils.ip.IpUtils;
import com.hckjsec.common.utils.spring.SpringUtils;
import com.hckjsec.official.domain.OfficialLogininfor;
import eu.bitwalker.useragentutils.UserAgent;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;
import java.util.TimerTask;
@Component
public class OfficialLoginLogService {
    @Autowired
    private IOfficialLogininforService officialLogininforService;


    @Async
    public void sendWebOfficialLog(UserAgent userAgent,String ip) {
        try {
                  String address = AddressUtils.getRealAddressByIP(ip);
                  // 获取客户端操作系统
                  String os = userAgent.getOperatingSystem().getName();
                  // 获取客户端浏览器
                  String browser = userAgent.getBrowser().getName();
                  // 封装对象
                  OfficialLogininfor officialLogininfor = new OfficialLogininfor();
                  officialLogininfor.setIpaddr(ip);
                  officialLogininfor.setLoginLocation(address);
                  officialLogininfor.setBrowser(browser);
                  officialLogininfor.setOs(os);
                  officialLogininfor.setLoginTime(DateUtils.getNowDate());
                  officialLogininforService.insertOfficialLogininfor(officialLogininfor);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
